﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FazaDemo.BL.SubDomains;
using FazaDemo.Data;

namespace FazaDemo.BL.Services
{
    class MenuConverter
    {

        private readonly IList<TS_SYS_EC_MENU> _loadedMenuItems;

        public MenuConverter(IList<TS_SYS_EC_MENU> loadedMenuItems)
        {
            _loadedMenuItems = loadedMenuItems;
        }

        public IList<MenuItem> BuildMenuItems()
        {
            var resultItems = new List<MenuItem>();
            var routes = new List<string>();
            foreach (var item in _loadedMenuItems)
            {
                if (RoutesStorage.Names.Contains(item.NM))
                    routes.Add(RoutesStorage.Routes[RoutesStorage.Names.IndexOf(item.NM)]);
                else
                    routes.Add(null);
                resultItems.Add(new MenuItem
                {
                    Id = Convert.ToInt32(item.MENU_TAG),
                    ParentId = item.PARENT,
                    Kind = item.KIND,
                    Text = item.NM, 
                    Route = routes[routes.Count - 1], 
                    NumEcq = item.NUM_ECQ
                });
            }
            return resultItems;
        }

    }
}
